package com.xatl.simulated.controller;



import com.xatl.simulated.client.MqttPublishClient;
import com.xatl.simulated.client.MqttSubscribeClient;
import com.xatl.simulated.constant.MqttPropertiesUtils;
import com.xatl.simulated.response.MyDeviceData;
import com.xatl.simulated.util.JsonUtil;
import com.xatl.simulated.util.NumberUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.*;

/**
 * @author pandi
 * @create 2020-11-06 17:22
 */

@Configuration
@EnableScheduling
public class SendToMqttData {


    @Autowired
    private MqttPropertiesUtils mqttPropertiesUtils;

    @Scheduled(cron = "0/10 * * * * ?")
    public void SendToMqtt(){

        HashMap<String,List<MyDeviceData>> HashMap = new HashMap<>();


        HashMap.put("1000",NumberUtil.random());
        HashMap.put("1001",NumberUtil.random());
        HashMap.put("1007",NumberUtil.random());
        HashMap.put("1018",NumberUtil.random());

//
        String s = JsonUtil.objectToJson(HashMap);
        //发布方法
//        MqttPublishClient.publish(mqttPropertiesUtils.getTopic(),mqttPropertiesUtils.getQos(),s);
        //订阅方法
        MqttSubscribeClient.subscribe(mqttPropertiesUtils.getTopic(),mqttPropertiesUtils.getQos());

    }



}
